package com.example.demo.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * knife4j的配置类
 */
@Configuration
@EnableSwagger2
public class Knife4jConfig {
    //Swagger界面中显示的基本信息
    private ApiInfo apiInfo() {
        //配置基本信息
        Contact briup = new Contact("briup", "http://www.briup.com/index.php/", "briup@briup.com");
        return new ApiInfoBuilder()
                .title("杰普网上商城用户端") // 标题
                .description("用户操作的相关接口") // 描述
                .contact(briup) // 基本信息
                .version("v1.0") // 版本
                .build(); // 构建
    }

    //配置Controller的包路径
    @Bean
    public Docket createRestApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                // apis里面的字符串，必须是你自己的Controller所在的包路径
                .apis(RequestHandlerSelectors.basePackage("com.example.demo.web"))
                .paths(PathSelectors.any())
                .build();
    }

}
